<?php
class VoteModel extends Model {
	protected $tableName = 'vote';

	public function getVoteList($post) {
		$order = 'id DESC';
		$limit = '20';
		$map   = array();
		$field = '*';

		//根据POST，组装查询条件
		if(!empty($post['id'])) {
			$map['id'] = array('in', $post['id']);
		}
		if(!empty($post['userId'])) {
			$map['uid'] = array('in', $post['userId']);
		}
		if(!empty($post['key'])) {
			$map['title'] = array('like', $post['key']);
		}
		if(isset($post['vote_type']) && $post['vote_type'] <= 1) {
			$map['type'] = ($post['vote_type'] == 0) ? 0 : array('neq', 0);
		}
		if(isset($post['is_anonymous']) && $post['is_anonymous'] <= 1) {
			$map['is_anonymous'] = intval($post['is_anonymous']);
		}
		if(isset($post['app']) && $post['app'] != 0) {
			if($post['app'] == '1') {
				$map['app'] = 'bbs';
				$map['groupId'] = 0;
			}else if($post['app'] == '2') {
				$map['app'] = 'bbs';
				$map['groupId'] = array('neq', 0);
			}
		}
		if(!empty($post['field']) && !empty($post['order'])) {
			$order = $post['field'] . ' ' . $post['order'];
		}
		if(!empty($post['limit'])) {
			$limit = intval($post['limit']);
		}
		
		$res = $this->where($map)->field($field)->order($order)->findPage($limit);
		return $res;
	}
}
?>